<template>
    <z-block url="/do/list/task" :params="params">
        <template #default="task">
            <el-tab-pane label="履约任务" name="perform">
                <z-action label='添加任务' mode='dialog' :data="params" :fields="putTaskFields" type='primary'
                          url='/do/put/task'/>
                <div class="form-spacing"></div>
                <el-empty v-if="task == null" description="暂无数据"/>
                <el-timeline style="max-width: 600px">
                    <el-timeline-item v-for="(activity, index) in task" :key="index"
                                      :color="activity.status === 1 ? '#0bbd87' : '#FF0000'"
                                      :timestamp="new Date(activity.createGmt * 1000).toLocaleString()" placement="top">
                        <el-card>
                            <el-descriptions column="1">
                                <el-descriptions-item label="任务id">
                                    <z-text type="primary" :modelValue="activity.id"
                                            emit="taskDetail"/>
                                </el-descriptions-item>
                                <el-descriptions-item label="任务名称">{{ activity.title }}</el-descriptions-item>
                                <el-descriptions-item label="任务类型">
                                    <z-dict readonly :modelValue="activity.type" code="cfg_taskType"/>
                                </el-descriptions-item>
                                <el-descriptions-item label="任务执行人">
                                    <z-avatar :value="activity.executor" :plain="false"/>
                                </el-descriptions-item>
                                <el-descriptions-item label="任务状态">
                                    {{ activity.status === 0 ? '待完成' : '已完成' }}
                                </el-descriptions-item>
                                <el-descriptions-item label="任务说明">
                                    {{ activity.explain }}
                                </el-descriptions-item>
                            </el-descriptions>
                            <z-action label='编辑' mode='dialog' :fields=patchTaskFields link :data="activity"
                                      url='/do/patch/task'
                                      includeTitle='r'/>
                            <z-action label='删除' mode='confirm' link :data="activity" url='/do/delete/task'/>
                        </el-card>
                    </el-timeline-item>
                </el-timeline>
            </el-tab-pane>
        </template>
    </z-block>
</template>

<script>


export default {
    props: {
        params: Object,
    },
    data() {
        return {
            putTaskFields: [
                {label: "任务名称", name: "title"},
                {label: "任务类型", name: "type", code: "cfg_taskType"},
                {label: "开始时间", name: "start", type: "date"},
                {label: "结束时间", name: "end", type: "date"},
                {label: "任务执行人", name: "executor", type: "user"},
                {label: "任务说明", name: "explain"},
                {label: "附件", name: "file", type: "attach"},
                {label: "关联合同", name: "contractId", default: this.params.contractId, visible: false}
            ],
            patchTaskFields: [
                {label: "任务名称", name: "title"},
                {label: "任务类型", name: "type", code: "cfg_taskType"},
                {label: "开始时间", name: "start", type: "date"},
                {label: "结束时间", name: "end", type: "date"},
                {label: "任务执行人", name: "executor", type: "user"},
                {label: "任务说明", name: "explain"},
                {label: "附件", name: "file", type: "attach"},
                {label: "完成内容", name: "finishContext"},
                {label: "完成附件", name: "finfishFile", type: "attach"},
                {label: "关联合同", name: "contractId", default: this.params.contractId, visible: false}
            ],
        }
    },
}
</script>
<style scoped>
.form-spacing {
    margin: 10px 0;
    height: 0;
    position: relative;
}
</style>
